$(document).ready(function(){
item();
//导航栏
	//伸缩
	$("#blogStrong").click(function(){stretch($('#myBlogUl'),$('#blback'));});
	$("#noticeStrong").click(function(){stretch($('#myNoticeUl'),$('#noback'));});
	//选中变色 + 选中事件
		$(".navLi").click(function(){
			var index = $(".navLi").index(this);
			changeColor(index);
		});
		//写日志
		$("#toWrite").click(function(){
			my = 1;
			clearTips();
			$('#fixed').html("");
			$("#loadingTip").css("display","inline-block");
			$("#fixed").load("Blogs/write",null,function(){
				$("#loadingTip").css("display","none");
				KE.init({
						id : 'textitem',
						width : '100%',
						resizeMode : 1
				});
				KE.create('textitem');
				$("#wheader").css("display","block");
				// if(isEdit){
					// $('#BlogTitle').attr('value',title[editIndex]);
					// KE.html('textitem',bigContent[editIndex]);
					// $('#tagName').attr('value',tag[editIndex]);
					// document.getElementById("categories")[cID[editIndex] - 1].selected = true;
					// isEdit = 0;
				// }
			});
		});
		//所有日志
		$("#allBlog").click(function(){
			stretchli($(".mytag"),$(".liback:eq(0)"));
		});
		$(".mytag").click(function(){
			my = 1;
			isdraft = 0;
			clearTips();
			$('#fixed').html("");
			$("#fixedItem").css("display","block");
			$("#loadingTip").css("display","inline-block");
			if($(".mytag").index(this) == 0){
				$.getJSON("Blogs/show_user_blog",{count:9999999},function(json){
					successfun(json);
				});
			}
			else{
				$.getJSON("Blogs/show_user_blog_by_category",{cid:$(this).attr('value')},function(json){
					successfun(json);
				})
			}
		})
		//草稿箱
		$("#draft").click(function(){
			my = 2;
			isdraft = 1;
			clearTips();
			$('#fixed').html("");
			$("#loadingTip").css("display","inline-block");
			$.getJSON("Blogs/show_drafts",function(json){
				successfun(json);
			})
		});
		//收藏夹
		$("#store").click(function(){
			my = 0;
			clearTips();
			$('#fixed').html("");
			$("#loadingTip").css("display","inline-block");
			$.getJSON("Collects/show_keep",{count:"10"},function(json){
				successfun(json);
			})
		});
		//添加分享
		$("#share").click(function(){
			my = 0;
			clearTips();
			$('#fixed').html("");
			$("#loadingTip").css("display","inline-block");
			$.getJSON("Shares/show_share",{count:"10"},function(json){
				successfun(json);
			})
		})
		//添加关注
		$("#myNoticeMan").click(function(){
			stretchli($(".noticePerson"),$(".liback:eq(1)"));
		});
		$(".noticePerson").click(function(){
			my = 0;
			clearTips();
			$('#fixed').html("");
			$("#loadingTip").css("display","inline-block");
			$.getJSON("Blogs/show_follow_blog",{follow_id:$(this).attr('value')},function(json){
				successfun(json);
			})
		});
		$("#myNoticeBlog").click(function(){
			stretchli($(".noticePost"),$(".liback:eq(2)"));
		});
		$("#toNotice").click(function(){
			clearTips();
			$('#fixed').html("<div id='hot'></div>");
			$("#loadingTip").css("display","inline-block");
			$.get("Categories/display_follow",function(json){
				$('#hot').html('<div id="Fdiv">' + json + '</div>');
				$.get("Categories/display_tag",function(data){
					$('#hot').append('<div id="Tdiv">' + data + '</div>');
					$("#loadingTip").css("display","none");
					changeN();
					changeT();
					addFollows();
					getByTag();
					toViewOthers();
				});
			})
		});
//查看个人资料
	$("#personal").click(function(){
		clearTips();
		$('#fixed').html("");
		$("#loadingTip").css("display","inline-block");
		$.get("Userinfos/modify",function(data){
			$("#fixed").html(data);
			$("#loadingTip").css("display","none");
		});
	});
//默认搜索
	$("#searchBut").click(function(){
		my = 0;
		if($("#searchinput").val() == "搜博客，搜标签，找人") return;
		if($("#searchinput").val()!='')
			clickToSea("search/nickname",seaNickName);
	});
//点击弹出条件,按条件搜索
	$("#searchinput").keyup(function(){
		if(len($("#searchinput").val()) > 14){
			$(".redLab").html(searchL = $("#searchinput").val().substr(0,elevenChar) + "..");
		}
		else
			$(".redLab").html($("#searchinput").val());
		if($("#searchinput").val() == '')
			$("#selectToSea").slideUp();
		else
			$("#selectToSea").slideDown();
	});
	$("#searchinput").focus(function(){
		if($("#searchinput").val() == "搜博客，搜标签，找人"){
			$("#searchinput").attr('value','');
			$("#searchinput").css('color','#000');
		}
		if($("#searchinput").val() != '')
			$("#selectToSea").slideDown();
	});
	$("#searchinput").blur(function(){
		$("#selectToSea").slideUp();
		if($("#searchinput").val() == ""){
			$("#searchinput").attr('value','搜博客，搜标签，找人');
			$("#searchinput").css('color','#666');
		}
	});
	$("#seaBlog").click(function(){
		my = 0;
		clickToSea("search/content",seaBlog);
	});
	$("#seaTag").click(function(){
		my = 0;
		clickToSea("search/tag",seaTag);
	});
	$("#seaPerson").click(function(){
		my = 0;
		clickToSea("search/nickname",seaNickName);
	});

});



//导航已变色li
	var now = $(".lia:eq(0)");
//文章存储
	var isBig = new Array();
	var fixedHtml;
	var title = new Array();
	var bigContent = new Array();
	var tag = new Array();
	var blogID = new Array();
	var userID = new Array();
	var cID = new Array();
	var readForm = 1;
	var elevenChar;
	var searchL;
	var my = 0;
	var isdraft = 0;
	//var isDelete = 0;
	//var isEdit = 0;
	var editIndex;
	var pageN = 2,pageT = 2;
//主页面辅助
	function item(){
		//获取面板高度
		var bwidth = window.innerWidth;
		var bheight = window.innerHeight;
		var bwidthnow = 0;
		var bheightnow = 0;
		//设置面板高度
		window.onload = function(){
			$("#mainContent").css("width",bwidth - '250');
			$("#maintable").css("width",bwidth - '250');
			$("#fixed").css("height",bheight - '103')
			$("#mainNavigation").css("height",bheight - '72');
		};
		//检查窗口大小,保证窗口全屏
		window.onresize = function(){
			bwidthnow = window.innerWidth;
			bheightnow = window.innerHeight;
			if(document.getElementById("mainNavigation").style.display!= "none"){
				$("#mainContent").css("width",bwidthnow - '250');
				$("#maintable").css("width",bwidthnow - '250');
				$("#fixed").css("height",bheightnow - '103')
				$("#mainNavigation").css("height",bheightnow - '72');
				$(".infDiv").css("width",bwidthnow - '400');
			}
			else{
				$("#mainContent").css("width",bwidthnow);
				$("#maintable").css("width",bwidthnow);
				$("#fixed").css("height",bheightnow - '103')
				$("#mainNavigation").css("height",bheightnow - '72');
				$(".infDiv").css("width",bwidthnow - '150');
			}
		};
	//左边面板的变色,隐藏和出现
		$("#itd").mouseover(function(){
			$("#itd").css("background-color","#ccf");
			$("#indent").css("background-color","#ccf");
			if((document.getElementById("mainNavigation").style.display== "none"))
				$("#indent").css("border-color","#ccf #ccf #ccf #000");
			else
				$("#indent").css("border-color","#ccf #000 #ccf #ccf");
		})
		$("#itd").mouseout(function(){
			$("#itd").css("background-color","#ddf");
			$("#indent").css("background-color","#ddf");
			if((document.getElementById("mainNavigation").style.display== "none"))
				$("#indent").css("border-color","#ddf #ddf #ddf #000");
			else
				$("#indent").css("border-color","#ddf #000 #ddf #ddf");
		})
		$("#itd").click(function(){
			if(document.getElementById("mainNavigation").style.display== "none"){
				bwidth = window.innerWidth;
				bheight = window.innerHeight;
				$("#mainContent").css("width",bwidth - '250');
				$("#maintable").css("width",bwidth - '250');
				$(".infDiv").css("width",bwidth - '400');
				$("#mainNavigation").css("display","block");
				$("#mainContent").css("margin-left","250px");
				$("#indent").css("border-color","#ddf #000 #ddf #ddf");
				$("#indent").css("border-width","10px 10px 10px 0");
				}
			else{
				bwidth = window.innerWidth;
				bheight = window.innerHeight;
				$("#mainContent").css("width",bwidth);
				$("#maintable").css("width",bwidth);
				$(".infDiv").css("width",bwidth - '150');
				$("#mainNavigation").css("display","none");
				$("#mainContent").css("margin-left","0");
				$("#indent").css("border-color","#ddf #ddf #ddf #000");
				$("#indent").css("border-width","10px 0 10px 10px");
			}
		})
}
//函数
	//读博客
	function pushBlogs(blogjson,json){
		$("#wheader").css("display","none");
		isBig.splice(0);
		saveBlog(json);
		$.each(json, function(key, val) {
			var tagHandle = json[key]['Blog']['keywords'];
			var tagTemp = tagHandle.split(" ");
			for (var i = 0;i < tagTemp.length;i++){
				tagTemp[i] = '<a href="javascript:void(0)" class="tagClass">' + tagTemp[i] + '</a>' + '&nbsp;&nbsp;';
			};
			tagHandle = tagTemp.join('');
			var postStr = '<div class="showtitle"><a href="javascript:void(0)" class="titleA">' +
					json[key]['Blog']['title'] +
					'</a></div>' +
					'<div><div class="left"><span class="leftitm">作者: <a class="nicknameA" href="javascript:void(0)">' +
					json[key]['Blog']['nickname'] +
					'</a></span>&nbsp;&nbsp;<span class="leftitm">时间: ' +
					json[key]['Blog']['dateline'] +
					'</span>&nbsp;&nbsp;<span class="leftitm viewTime">访问数量: ' +
					json[key]['Blog']['views'] +
					'</div></div><div class="showtext">' +
					bigContent[key] +
					'</div><div class = "postInf">标签&nbsp;&nbsp;&nbsp;<span class="postTag">'+ 
					tagHandle +
					'</span></div>'
			if(my)
				blogjson.push(
					'<div class = "post"><div class="topItem"><label class="toEdit">编辑</label>&nbsp;&nbsp;&nbsp;<label class="toDelete">删除</label></div>'
					+ postStr + '</div>'
				);
			else
				blogjson.push(
					'<div class = "post">' +
					postStr +
					'<div class="commentdiv"><textarea class="commenttextarea"></textarea></div><div class="bottomItem"><label class="commentBtn">评论</label>&nbsp;&nbsp;&nbsp;<label class="shareBtn">分享</label>&nbsp;&nbsp;&nbsp;<label class="storeBtn">收藏</label></div></div>'
				);
		})
	}
	//导航伸缩
	function stretch(ul,ulback){
		if(ul.css('display')!='none'){
			ul.slideUp("normal");
			ulback.css("background-image","url('img/stretch.png')");
		}
		else{
			ul.slideDown("normal");
			ulback.css("background-image","url('img/back.png')");
		}
	}
	function stretchli(li,liback){
		if(li.css('display')!='none'){
			li.slideUp("normal");
			liback.css("background-image","url('img/listretch.png')");
		}
		else{
			li.slideDown("normal");
			liback.css("background-image","url('img/liback.png')");
		}
	}
	function slideTog(part){
		part.slideToggle("normal");
	}
	//导航选中变色
	function changeColor(index){
		var obj = '.lia:eq(' + index + ')'
		now.css("background-color","transparent");
		$(obj).css("background-color","#ccf");
		now = $(obj);
	}
	//blog存储
	function saveBlog(json){
		bigContent.splice(0);
		title.splice(0);
		blogID.splice(0);
		userID.splice(0);
		tag.splice(0);
		cID.splice(0);
		for(var i = 0;i < json.length;i++){
			bigContent.push(json[i]['Blog']['content']);
			title.push(json[i]['Blog']['title']);
			tag.push(json[i]['Blog']['keywords']);
			blogID.push(json[i]['Blog']['id']);
			userID.push(json[i]['Blog']['uid']);
			cID.push(json[i]['Blog']['cid']);
		}
	}
	//显示方式
	function toBig(){
		$(".titleA").click(function(){
			var index = $(".titleA").index(this);
			if (isBig[index] != 1){
				var ss = ".showtext" + ":eq(" + index + ")";
				$(ss).css("max-height","none");
				isBig[index] = 1;
				var bi = ".bottomItem" + ":eq(" + index + ")";
				$(bi).css("display","block");
			}
		});
	}
	function allToBig(){
		$(".showtext").css("max-height","none");
		$(".bottomItem").css("display","block");
		for(var i = 0;i < isBig.length;i++)
			isBig[i] = 1;
	}
	function allToSmall(){
		$(".showtext").css("max-height","185px");
		$(".bottomItem").css("display","none");
		for(var i = 0;i < isBig.length;i++)
			isBig[i] = 0;
	}
	function setForm(obj1,obj2){
		obj1.css({"font-weight":"600","cursor":"default","color":"#000"});
		obj2.css({"font-weight":"100","cursor":"pointer","color":"#33f"});
	}
	function changeReadForm(){
		$("#expand").click(function(){
			if(readForm){
				allToBig();
				setForm($(this),$("#list"));
				readForm = 0;
			}
		})
		$("#list").click(function(){
			if(!readForm){
				allToSmall();
				setForm($(this),$("#expand"));
				readForm = 1;
			}
		})
	}
	//评论框
	function toComment(){
		$(".commentBtn").click(function(){
			var index = $(".commentBtn").index(this);
			var comobj = ".commentdiv:eq(" + index + ")";
			$(comobj).slideToggle("normal");
		});
	}
	//收藏和分享,删除,编辑
	function toStore(){
		$(".storeBtn").click(function(){
			var index = $(".storeBtn").index(this);
			$.getJSON("Collects/store",{blog_id:blogID[index]},function(){
				$("#sstore").css("display","inline-block");
				$.get("Categories/show_navigation",function(json){
					$("#reflash").html(json);
					collection();
					item();
				})
				var t = setTimeout('$("#sstore").css("display","none")',2000);
			});
		});
	}
	function toShare(){
		$(".shareBtn").click(function(){
			var index = $(".shareBtn").index(this);
			$.getJSON("Shares/store",{blog_id:blogID[index]},function(data){
				if(data!=0){
					$("#sshare").css("display","inline-block");
					var t = setTimeout('$("#sshare").css("display","none")',2000);
				}
			});
		});
	}
	function toEdit(){
		$(".toEdit").click(function(){
			editIndex = $(".toEdit").index(this);
			$('#fixed').html("");
			$("#loadingTip").css("display","inline-block");
			if(isdraft!=0){
				$.get("Blogs/edit",{draft_id:blogID[editIndex]},function(json){
					editHandle(json);
				});
			}
			else{
				$.get("Blogs/edit",{id:blogID[editIndex]},function(json){
					editHandle(json);
				});
			}
		});
	}
	function editHandle(json){
		if(json != 0){
			$('#fixed').html(json);
			$("#loadingTip").css("display","none");
			KE.init({
					id : 'textitem',
					width : '100%',
					resizeMode : 1
			});
			KE.create('textitem');
			$("#wheader").css("display","block");
		}
		else{
			$("#loadingTip").css("display","none");
			$("#faileLoad").css("display","inline-block");
		}
	}
	function toDelete(){
		$(".toDelete").click(function(){
			var index = $(".toDelete").index(this);
			if(confirm("真的要删除这条博客吗?")){
				if(my == 1){
					$.get("Blogs/delete",{blog_id:blogID[index]},function(data){
						toDeleteItem(data);
					});
				}
				else
					$.get("Blogs/delete",{draft_id:blogID[index]},function(data){
						toDeleteItem(data);
					});
			}
		})
	}
	function toDeleteItem(data){
		if(data!=0){
			$("#sdelete").css("display","inline-block");
			alert("删除成功");
			var t = setTimeout('$("#sdelete").css("display","none")',2000);
			$.get("Categories/show_navigation",function(json){
				$("#reflash").html(json);
				collection();
				item();
			})
			$(".mytag:eq(0)").click();
		}
		else{
			$("#fdelete").css("display","inline-block");
		}
	}
	//按标签获取blog,按订阅标签获取blog
	function getByTag(){
		$(".tagClass").click(function(){
			my = 0;
			clearTips();
			var thisName = $(this).html();
			$('#fixed').html("");
			$("#loadingTip").css("display","inline-block");
			$.getJSON("Blogs/show_by_tag",{tag:thisName},function(json){
				successfun(json);
			})
		})
	}
	function getByTag2(){
		$(".noticeA").click(function(){
			my = 0;
			clearTips();
			var thisName = $(this).html();
			$('#fixed').html("");
			$("#loadingTip").css("display","inline-block");
			$.getJSON("Blogs/show_by_tag",{tag:thisName},function(json){
				successfun(json);
			})
		})
	}
	//getJSON封装
	function successfun(json){
				var blogjson = [];
				pushBlogs(blogjson,json);
				fixedhtml = blogjson.join('');
				$('#fixed').html(fixedhtml);
				if(isdraft){
					$(".viewTime").remove();
				}
				toBig();
				toComment();
				changeReadForm();
				toViewOthers();
				addId();
				toStore();
				toShare();
				toDelete();
				toEdit();
				$("#seaResTipDiv").css("display","none");
				$("#itemLab").css("display","none");
				$("#fixedItem").css("display","block");
				if(!readForm)
					allToBig();
				getByTag();
				$("#loadingTip").css("display","none");
	}
	//点击条件搜索
	function clickToSea(url,fun){
		$('#fixed').html("");
		if(searchL)
			$('.seaResTip').html(searchL);
		else
			$('.seaResTip').html($("#searchinput").val());
		$("#loadingTip").css("display","inline-block");
		var seaName = $("#searchinput").val();
		$.get(url,{sqlName:seaName},function(json){
			fun(json);
		});
	}
	//sea处理函数
	function seaNickName(json){
		clearTips();
		$("#seaResTipDiv").css("display","block");
		if(json!='0'){
			$("#fixed").html(json);
			addFollows();
			$("#loadingTip").css("display","none");
		}
		else{
			$("#loadingTip").css("display","none");
			$("#fixed").html('<div id="noRes"><div id="noResTip"><label>抱歉,找不到"<span class="seaResTip"></span>"的相关结果</label><br /><br /><label><strong>建议 :</strong><br />请尽量输入常用词<br />请尽量使用简洁的关键词</label></div></div>');
			$('.seaResTip').html($("#searchinput").val());
		}
	}
	function seaTag(json){
		clearTips();
		$("#fixedItem").css("display","block");
		if(json!='0'){
			json = eval(json);
			successfun(json);
			}
		else{
			$("#seaResTipDiv").css("display","none");
			$("#loadingTip").css("display","none");
			$("#fixed").html('<div id="noRes"><div id="noResTip"><label>抱歉,找不到"<span class="seaResTip"></span>"的相关结果</label><br /><br /><label><strong>建议 :</strong><br />请尽量输入常用词<br />请尽量使用简洁的关键词</label></div></div>');
			$('.seaResTip').html($("#searchinput").val());
		}
		$("#itemLab").css("display","inline-block");
	}
	function seaBlog(json){
		clearTips();
		$("#fixedItem").css("display","block");
		if(json!='0'){
			json = eval(json);
			successfun(json);
			}
		else{
			$("#seaResTipDiv").css("display","none");
			$("#loadingTip").css("display","none");
			$("#fixed").html('<div id="noRes"><div id="noResTip"><label>抱歉,找不到"<label class="seaResTip"></label>"的相关结果</label><br /><br /><label><strong>建议 :</strong><br />请尽量输入常用词<br />请尽量使用简洁的关键词</label></div></div>');
			$('.seaResTip').html($("#searchinput").val());
		}
		$("#itemLab").css("display","inline-block");
	}
	//分析字符个数
	function len(s){
		var l = 0;
		var a = s.split("");
		for(var i=0;i<a.length;i++){
			if (a[i].charCodeAt(0)<299){
				l++;
				if(l == 13)
					elevenChar = i+1;
			}
			else{
				l+=2;
				if(l == 14)
					elevenChar = i+1;
			}
			
		}
		return l;
	}
	//点击查看他人资料
	function toViewOthers(){
		clearPart();
		$(".nicknameA").click(function(){
			var index = $(".nicknameA").index(this);
			$('#fixed').html("");
			clearTips();
			$("#loadingTip").css("display","inline-block");
			$.get("Userinfos/view_imf",{uid:userID[index]},function(data){
				$("#fixed").html(data);
				$("#loadingTip").css("display","none");
			});
		});
		$(".nickName_id_A").click(function(){
			var index = $(".nickName_id_A").index(this);
			var PersonObj = ".uid':eq(" + index + ")";
			var addPerson = $(PersonObj).html();
			$('#fixed').html("");
			clearTips();
			$("#loadingTip").css("display","inline-block");
			$.get("Userinfos/view_imf",{uid:addPerson},function(data){
				$("#fixed").html(data);
				$("#loadingTip").css("display","none");
			});
		});
		$(".avatarDiv").click(function(){
			var index = $(".avatarDiv").index(this);
			var PersonObj = ".uid':eq(" + index + ")";
			var addPerson = $(PersonObj).html();
			$('#fixed').html("");
			clearTips();
			$("#loadingTip").css("display","inline-block");
			$.get("Userinfos/view_imf",{uid:addPerson},function(data){
				$("#fixed").html(data);
				$("#loadingTip").css("display","none");
			});
		});
	}
	//blog focus加id
	function addId(){
		$(".post").mouseover(function(){
			$(this).attr("id","readingPost");
		});
		$(".post").mouseout(function(){
			$(this).attr("id",null);
		});
	}
	//换一批
	function changeN(){
		$("#changeN").click(function(){
			$.get("Categories/display_follow/page:" + pageN,function(json){
				$('#Fdiv').html(json);
				pageN++;
				getByTag();
				changeN();
				addFollows();
			});
		});
	}
	function changeT(){
		$("#changeT").click(function(){
			$.get("Categories/display_tag/page:" + pageT,function(json){
				if(json != 0){
					$('#Tdiv').html(json);
					pageT++;
					getByTag();
					changeT();
					addFollows();
				}
				else
					alert("已经是最后一批");
			});
		});
	}
	//添加订阅
	function addFollows(){
		clearPart();
		$(".toFollowBtnT").click(function(){
			var index = $(".toFollowBtnT").index(this);
			var tagObj = ".addTagClass':eq(" + index + ")";
			var addTagName = $(tagObj).html();
			$.get("categories/add_tag",{tag:addTagName},function(data){
				if(data != 0){
					$.get("Categories/show_navigation",function(json){
						$("#reflash").html(json);
					})
					$("#sadd").css("display","inline-block");
					var t = setTimeout('$("#sadd").css("display","none")',2000);
					item();
					collection();
				}
				else
					$("#fadd").css("display","inline-block");
			})
		});
		$(".toFollowBtnN").click(function(){
			var index = $(".toFollowBtnN").index(this);
			var PersonObj = ".uid':eq(" + index + ")";
			var addPerson = $(PersonObj).html();
			$.get("categories/add_follow",{follow_id:addPerson},function(data){
				if(data != 0){
					$.get("Categories/show_navigation",function(json){
						$("#reflash").html(json);
					})
					$("#sadd").css("display","inline-block");
					var t = setTimeout('$("#sadd").css("display","none")',2000);
					item();
					collection();
				}
				else
					$("#fadd").css("display","inline-block");
			})
		});
		$(".toFollowBtn").click(function(){
			var index = $(".toFollowBtn").index(this);
			var PersonObj = ".uid':eq(" + index + ")";
			var addPerson = $(PersonObj).html();
			$.get("categories/add_follow",{follow_id:addPerson},function(data){
				if(data != 0){
					$.get("Categories/show_navigation",function(json){
						$("#reflash").html(json);
					})
					$("#sadd").css("display","inline-block");
					var t = setTimeout('$("#sadd").css("display","none")',2000);
					item();
					collection();
				}
				else
					$("#fadd").css("display","inline-block");
			})
		});
	}
	//判断是否第一次登陆
	function firstlogin(){
		if(location.hash == '#firstLogin'){
			$.get('Userinfos/personalImf',function(){
				launch();
				location.hash = '';
			})
		}
	}
	//判断为true弹出层
	function launch(){
		try{
			$("body").append("<div id='L_overlay'></div><div id='L_window'></div>");
			$("#L_overlay").css("opacity","0.6");
		    $("#L_overlay").css("filter","alpha(opacity=60)");
		    $("#L_overlay").css("-moz-opacity","0.6");
			$(window).resize(L_position);
			$("body").append("<div id='L_load'><div id='L_loadContent'><img src=''></div></div>");
			$("#L_overlay").show();
			
			var url = "Userinfos/personalImf?height=370&width=1080";
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = parseQuery( queryString );
			
			L_width = (params['width']*1)+30;
			L_height = (params['height']*1)+40;
			contentW = L_width - 30;
			contentH = L_height - 45;
			
			$("#L_window").append("<div id='L_closeWindow'><a href='' id='L_closeWindowbotton'>关闭</a></div><div id='L_content' style='width:"+contentW+"px;height:"+contentH+"px'></div>");
			$("#L_closeWindowbotton").click(L_remove);
			$("#L_content").load(url,function(){
				L_position();
				$("#L_load").remove();
				$("#L_window").slideDown("normal");
				selectDate(); //加载出生日期
				$("#div1").css("display","none");
				$("#div2").css("display","none");
				lightout();//突出所在编辑处
				$("#pass").click(L_remove);  //跳过
				shiftPage();  //换页
				});
		}
		catch(e){
			alert(e);
		}
		this.blur();
		return false;
	}
	function L_remove(){
	$("#L_window").fadeOut("fast",function(){
		$("#L_window,#L_load,#L_overlay").remove();
		})
		return false;
}
	function L_position(){
		var de = document.documentElement;
		var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
		var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
		
		if(window.innerHeight&&window.scrollMaxY){
			y = window.innerHeight + window.scrollMaxY;
		}
		else if(document.body.scrollHeight > document.body.offsetHeight)
			y = document.body.scrollHeight;
			else 
			y = document.body.offsetHeight;
		
		$("#L_window").css({width:L_width+"px", height:L_height+"px", left:((w-L_width)/2)+"px",top:((h-L_height)/2)+"px"});
		$("#L_overlay").css("height",y+"px");
	}
	function parseQuery(query){
		var param = new Object();
		if(!query) return param;
		var pairs = query.split(/[;&]/);
		for(var i=0;i<pairs.length;i++){
			var keyValue = pairs[i].split('=');
			if(!keyValue || keyValue.length != 2) continue;
			var key = unescape(keyValue[0]);
			var value = unescape(keyValue[1]);
			var value = value.replace(/\+/g,' ');
			param[key]=value;
		}
		return param;
	}
	var shiftPage = function(){
		var page = 0;
		var playnext = "";
		var playpre = "";
		var playnow = "";
		var picnext = "";
		var picpre = "";
		var picnow = "";
		var finish = false;
		var pagenum = function(page){
			playnow = "#div" + page;
			picnow = "#pic" + page + " img";
			if(page == 0){//没有上一步,这是第一页
				$("#pre a").css("color","#999");
				$("#pre a").css("text-decoration","none");
				$("#pre a").css("cursor","default");     //上一步文字的特效改变
				playnext = "#div" + (page+1);
				playpre = playnow;
				picnext = "#pic" + (page + 1) + " img";
				picpre = picnow;
				return;
				}
			if(page == 2){//没有下一步,这是最后一页
				$("#next a").hide();
				$("#submitId").show();
				playpre = "#div" + (page-1);
				playnext = playnow;
				picpre = "#pic" + (page-1) + " img";
				picnext = picnow;
				return;
			}
			playnext = "#div" + (page+1);
			playpre = "#div" + (page-1);
			picnext = "#pic" + (page + 1) + " img";
			picpre = "#pic" + (page - 1) + " img";
		}
			pagenum(page);
			$("#next").click(function(){
				if(page < 2){
				$(playnow).hide();
				$(playnext).show();
				$(picnow).attr("src","img/arrowBlue.png");
				$(picnext).attr("src","img/arrowOrg.png");
				page++;
				}
				if(page == 1){
				$("#pre a").css({"color":"#000","text-decoration":"underline"});
				$("#pre a").css("cursor","pointer");
				}
				pagenum(page);
				if(page == 2 && finish == false){
					finish = true;
				}
				else if(page == 2 && finish == true){
					L_remove();
					return;
				}
			});
				$('#submitId').click(function() {
					// 提交表单
					$('#ImfForm').ajaxSubmit();
					L_remove();
					// 为了防止普通浏览器进行表单提交和产生页面导航（防止页面刷新？）返回false
				return false;
			});
			$("#pre").click(function(){
				$(playnow).hide();
				$(playpre).show();
				$(picnow).attr("src","img/arrowBlue.png");
				$(picpre).attr("src","img/arrowOrg.png");
				if(page == 2)
					finish = false;
				if(page > 0)
				page--;
				if(page == 1){
				$(playnow).hide();
				$(playnext).show();
				}
				pagenum(page);
			});
	}

	//加载年，月，日的选择
function selectDate(){
	var s = "";
	for(var y = 1950; y < 2011 ;y++){
		s = "<option value='"+ y +"' class='year'>" + y + "</option>";
		$("#year").append(s);
	}
	for(var m = 1; m < 13; m++){
		s = "<option value='"+ m +"' class='month'>" + m + "</option>";
		$("#month").append(s);
	}
	for(var d = 1; d < 29; d++){
		s = "<option value='"+ d +"' class='day'>" + d + "</option>";
		$("#day").append(s);
	}
	$("#month").click(showDate);
}

var showDate = function(){
	if($('.day:eq(28)')){
		$(".day:gt(27)").detach();
	}
	//var y = document.getElementById("year").selectedIndex;
	var year = $(".year:selected").val();
	var month = $(".month:selected").val();
	var isLeapYear=function(year){
		if(year % 400 == 0 || (year % 4 == 0) && year % 100 != 0)
			return true;
		else 
			return false;
	}
		if(month != null){
			var s = "";
			var num = 30;
			switch(parseInt(month)){
				case 1:
				case 3:
				case 5:
				case 7:
				case 8:
				case 10:
				case 12: num = 31;break;
				case 2: if(isLeapYear(parseInt(year))) num = 29;
						else num = 28;
						break;
				default:break;
			}
			for(var d = 29; d <= num; d++){
				s = "<option value='"+ d +"' class='day'>" + d + "</option>";
				$("#day").append(s);
			}
		}
}
//当鼠标处于某一块的时候会突出
function lightout(){
	$(".perImfDiv").mouseover(function(){
		$(this).css("border","solid 3px #3e6de7");
	});
	$(".perImfDiv").mouseout(function(){
		$(this).css("border","solid 3px #FFF");
	});
}
//清空所有tips
function clearTips(){
	$("#loadingTip").css("display","none");
	$("#faileLoad").css("display","none");
	$("#sstore").css("display","none");
	$("#sdelete").css("display","none");
	$("#fdelete").css("display","none");
	$("#wheader").css("display","none");
	$("#sadd").css("display","none");
	$("#fadd").css("display","none");
	$("#seaResTipDiv").css("display","none");
	$("#itemLab").css("display","none");
}
//清空失败信息tips
function clearPart(){
	$("#faileLoad").css("display","none");
	$("#fdelete").css("display","none");
	$("#fadd").css("display","none");
}
//函数大集合
function collection(){
	toBig();
	toComment();
	changeReadForm();
	toViewOthers()
	addId();
	getByTag();
	getByTag2();
	toEdit();
	toDelete();
}